﻿
@{
    ViewBag.Title = "编辑讨论";
    Layout = "~/Views/Shared/_Member.cshtml";
}

<div class="row p10 bcolor" style="overflow:auto;">
    <div class="layui-col-md11 pt30">
        <form class="layui-form" id="dataForm">
            <div class="layui-form-item layui-hide">
                <label class="layui-form-label">讨论ID</label>
                <div class="layui-input-block">
                    <input type="text" name="ID" id="ID" class="layui-input" value="@ViewBag.discussId">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">讨论标题</label>
                <div class="layui-input-block">
                    <input type="text" name="Title" placeholder="请输入讨论标题" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">进入密码</label>
                <div class="layui-input-inline">
                    <input type="text" name="Password" placeholder="请输入进入密码" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">如需加密讨论请填写密码</div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">讨论内容</label>
                <div class="layui-input-block">
                    <div id="editor"></div>
                </div>
            </div>
            <div class="layui-form-item pt30">
                <div class="layui-input-block">
                    <a href="javascript:void(0)" class="layui-btn layui-btn-normal" onclick="javascript: { discuss.submit(); }">保存</a>
                    <a href="/Member/Discuss@(ViewBag.Suffix)" class="layui-btn layui-btn-primary">取消</a>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    var editor = new window.wangEditor('#editor');
    editor.customConfig.uploadImgServer = '/Base/WangEditorUpload';
    editor.customConfig.uploadImgMaxSize = 1024 * 1024;
    editor.customConfig.uploadImgMaxLength = 2;
    editor.customConfig.customAlert = function (info) {
        layer.msg(info);
    }
    editor.create();
    var discuss = new Discuss();
    $(function () {
        discuss.paras.articleId = $('#ID').val();
        if (discuss.paras.articleId) {
            discuss.initClassify();
        }
    });

    function Discuss() {
        this.paras = {
            articleId: null
        };
        this.initClassify = function () {
            $.post('/member/GetMemberArticleResult', this.paras, function (result) {
                $('#dataForm').setForm(result.data);
                editor.txt.html(result.data.Content);
            });
        };
        this.submit = function () {
            var paras = $('#dataForm').getForm();
            paras.Content = editor.txt.html();

            if (!paras.Title) {
                layer.msg('讨论标题不能为空');
                return;
            }
            if (!paras.Content) {
                layer.msg('讨论内容不能为空');
                return;
            }

            $.post('/member/UserEditDiscussResult', paras, function (result) {
                layer.confirm('保存成功', {
                    closeBtn: 0,
                    btn: ['确定']
                }, function () {
                    window.parent.parent.location = '/member/Discuss';
                });
            });
        };
    };

</script>